﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HRX.PayCenter.Common
{
    public static class StringHelper
    {
        /// <summary>
        /// 连接url
        /// </summary>
        /// <param name="urls"></param>
        /// <returns></returns>
        public static string ConcatUrl(params string[] urls)
        {
            List<string> list = new List<string>();
            foreach (var url in urls)
            {
                string temp = (url ?? "").Trim('/');
                if (string.IsNullOrEmpty(temp))
                {
                    continue;
                }
                list.Add(temp);
            }
            ExceptionHelper.ThrowIfNullOrEmpty(list, "url拼接为空");
            return string.Join("/", list.ToArray());
        }

        /// <summary>
        /// LogSDK的说明文档：http://192.168.101.244/publicDev/Log.Tcysys
        /// 说明：数据包错误堆栈信息最大为3072 字节，超过会自动截取
        /// </summary>
        /// <param name="str"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public static string CutIfTooLong(this string str, int len = 1500)
        {
            if (!string.IsNullOrEmpty(str) && str.Length > len)
            {
                return str.Substring(0, len);
            }

            return str;
        }

        public static string TrimOrEmpty(this string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return "";
            }

            return str.Trim();
        }
    }
}
